
#pyinstaller --onefile your_script.py

import docx
import os
import sys
from docx.shared import RGBColor
def add_header_footer(path):
    doc = docx.Document(path)
    section = doc.sections[0]
    header = section.header
    header_para = header.paragraphs[0]
    header_para.text = content
    header_para.runs[0].font.color.rgb = RGBColor(255, 0, 0)
    footer = section.footer
    footer_para = footer.paragraphs[0]
    footer_para.text = content
    footer_para.runs[0].font.color.rgb = RGBColor(255, 0, 0)
    doc.save(f"new\\{path}")

if __name__=="__main__":

    content = '池塘边素材网:www.ctbsc.cn ,每日更新150+篇公文素材，或添加客服微信:ctbsc2021'
    #content = '写益文荟网:www.xieyiwenhui.cn ,每日更新150+篇公文素材，或添加客服微信:xywenhui2025'

    current_dir = os.getcwd()
    if not os.path.exists(current_dir+"\\new"):
        os.mkdir(current_dir+"\\new")

    files = os.listdir(current_dir)
    for name in files:
        try:
            if name.endswith('docx'):
                add_header_footer(name)
                print(name+'-完成！')
        except Exception as e:
            print(name+'---------失败，失败原因：')
            print(e)
            continue

    input("请安任意键退出...")